package br.unesp.rc.rafaelt.business.services.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.unesp.rc.rafaelt.business.services.StudentServices;
import br.unesp.rc.rafaelt.business.to.StudentListTO;
import br.unesp.rc.rafaelt.business.to.StudentTO;
import br.unesp.rc.rafaelt.model.bean.Student;
import br.unesp.rc.rafaelt.model.dao.StudentDao;

@Service
@Scope(value = "singleton")
public class StudentServicesImpl implements StudentServices {
	
    @Autowired
    private StudentDao studentDao;
	
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	public StudentTO findById(final Long id) {
		Student student = studentDao.findById(id);
		
		StudentTO studentTO = new StudentTO(student.getIdStudent(),
											student.getFirstName(),
											student.getLastName(),
											student.getBirthday());
		return studentTO;
	}
	
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	public StudentListTO findAll() {
		/*List<Student> studentList = new ArrayList<Student>();
		studentList.add(new Student(1L, "John", "Smith", new Date()));
		studentList.add(new Student(2L, "Larry", "Parker", new Date()));
		studentList.add(new Student(3L, "Brad", "Sanders", new Date()));
		return new StudentListTO(studentList);*/
		//return studentDao.find(studentId);
		return null; 
	}

}